/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package it.polimi.registration.business.security.entity;

import java.io.Serializable;
import java.util.Calendar;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.MapsId;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import org.eclipse.persistence.annotations.Mutable;

/**
 *
 * @author Innotommy91
 */
@Entity
public class Invite implements Serializable {

    private static final long serialVersionUID = 1L;

    @EmbeddedId
    private InvitePK invitePK;

    @MapsId("event")
    @JoinColumn(referencedColumnName = "id")
    @ManyToOne(optional = false)
    private Event event;

    @MapsId("user")
    @JoinColumn(referencedColumnName = "email")
    @ManyToOne(optional = false)
    private User user;

    @NotNull(message = "May not be empty")
    @Temporal(TemporalType.TIMESTAMP)
    private Calendar creationTime;

    @NotNull
    private Integer status;

    public Invite() {
    }

    public Invite(InvitePK invitePK) {
        this.invitePK = invitePK;
        this.setStatus(InviteStatus.PENDING);
        this.creationTime = Calendar.getInstance();
    }

    public Calendar getCreationTime() {
        return creationTime;
    }

    public void setCreationTime(Calendar date) {
        this.creationTime = date;
    }

    public InvitePK getInvitePK() {
        return invitePK;
    }

    public void setInvitePK(InvitePK invitePK) {
        this.invitePK = invitePK;
    }

    public InviteStatus getStatus() {
        return InviteStatus.getType(this.status);
    }

    public void setStatus(InviteStatus status) {

        if (status == null) {
            this.status = null;
        } else {
            this.status = status.getId();
        }
    }

    public Event getEvent() {
        return event;
    }

    public void setEvent(Event event) {
        this.event = event;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

}
